package com.cskaoyan.servlet;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.StatGoodsVo;
import com.cskaoyan.bean.vo.StatOrderVo;
import com.cskaoyan.bean.vo.StatVo;
import com.cskaoyan.service.StatService;
import com.cskaoyan.service.StatServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/admin/stat/*")
public class AdminStatServelet extends WdBaseServlet /*extends HttpServlet */ {
    StatService statService=new StatServiceImpl();

    private BaseRespVo user(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Map> rows = statService.statUser();
        String[] columns = new String[]{"day", "users"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return BaseRespVo.ok(statVo);
    }

    private BaseRespVo order(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Map> rows = statService.statOrder();
        String[] columns = new String[]{"day","orders","customers","amount", "pcr"};
        StatOrderVo statOrderVo = new StatOrderVo();
        statOrderVo.setColumns(columns);
        statOrderVo.setRows(rows);
        return BaseRespVo.ok(statOrderVo);
    }
    private BaseRespVo goods(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Map> rows = statService.statGoods();
        String[] columns = new String[]{"day","orders","products","amount", "pcr"};
        StatGoodsVo statGoodsVo = new StatGoodsVo();
        statGoodsVo.setColumns(columns);
        statGoodsVo.setRows(rows);
        return BaseRespVo.ok(statGoodsVo);
    }

}